package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.TrustEnclosure;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HousingTrust;
import com.ruoyi.system.service.IHousingTrustService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 房屋情况Controller
 * 
 * @author ruoyi
 * @date 2021-06-16
 */
@RestController
@RequestMapping("/system/trust")
public class HousingTrustController extends BaseController
{
    @Autowired
    private IHousingTrustService housingTrustService;

    /**
     * 查询房屋情况列表
     */
//    @PreAuthorize("@ss.hasPermi('system:trust:list')")
    @GetMapping("/list")
    public TableDataInfo list(HousingTrust housingTrust)
    {
        startPage();
        List<HousingTrust> list = housingTrustService.selectHousingTrustList(housingTrust);
        return getDataTable(list);
    }

    /**
     * 导出房屋情况列表
     */
//    @PreAuthorize("@ss.hasPermi('system:trust:export')")
    @Log(title = "房屋情况", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HousingTrust housingTrust)
    {
        List<HousingTrust> list = housingTrustService.selectHousingTrustList(housingTrust);
        ExcelUtil<HousingTrust> util = new ExcelUtil<HousingTrust>(HousingTrust.class);
        return util.exportExcel(list, "trust");
    }

    /**
     * 获取房屋情况详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:trust:query')")
    @GetMapping(value = "/{htId}")
    public AjaxResult getInfo(@PathVariable("htId") Long htId)
    {
        return AjaxResult.success(housingTrustService.selectHousingTrustById(htId));
    }

    /**
     * 新增房屋情况
     */
//    @PreAuthorize("@ss.hasPermi('system:trust:add')")
    @Log(title = "房屋情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HousingTrust housingTrust)
    {
        if(housingTrustService.insertHousingTrust(housingTrust)>0){
            return AjaxResult.success(housingTrust);
        }else {
            return AjaxResult.error();
        }
    }

    /**
     * 修改房屋情况
     */
//    @PreAuthorize("@ss.hasPermi('system:trust:edit')")
    @Log(title = "房屋情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HousingTrust housingTrust)
    {
        return toAjax(housingTrustService.updateHousingTrust(housingTrust));
    }

    /**
     * 删除房屋情况
     */
//    @PreAuthorize("@ss.hasPermi('system:trust:remove')")
    @Log(title = "房屋情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{htIds}")
    public AjaxResult remove(@PathVariable Long[] htIds)
    {
        return toAjax(housingTrustService.deleteHousingTrustByIds(htIds));
    }
}
